//
//  TMTopView.m
//  TMFishTravel
//
//  Created by Playboy on 2017/10/12.
//  Copyright © 2017年 tmkj. All rights reserved.
//

#import "TMTopView.h"

static CGFloat const topViewHeight=60;

@interface TMTopView ()

@property (strong, nonatomic) IBOutlet UILabel *label;


@end

@implementation TMTopView

+ (TMTopView *)viewWithMessage:(NSString *)message {
    
    TMTopView *topView = [[[NSBundle mainBundle] loadNibNamed:@"TMTopView" owner:nil options:nil] lastObject];
    topView.frame = CGRectMake(0, -topViewHeight, kScreenWidth, topViewHeight);
    [topView configerMessage:message];
    return topView;
    
}

- (void)configerMessage:(NSString *)message {
    
    self.label.text = message;
    
}

#pragma mark - 动画
-(void)showViewWithCompletion:(void (^)(void))completion{
    [UIView animateWithDuration:0.3 animations:^{
        self.frame=CGRectMake(0, 0, kScreenWidth, topViewHeight);
    } completion:nil];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:0.3 animations:^{
            self.frame=CGRectMake(0, -topViewHeight, kScreenWidth, topViewHeight);
        } completion:^(BOOL finished) {
            if (completion) {
                completion();
            }
        }];
    });
}

@end
